<template>
	<view class="home">
		<view class="tab-box">
			<text :class="current == 0?'active':''" @click="current = 0">上架商品</text>
			<text :class="current == 2?'active':''" @click="current = 2">下架商品</text>
			<text :class="current == 1?'active':''" @click="current = 1">待审核商品</text>
			<text :class="current == 3?'active':''" @click="current = 3">未通过商品</text>
			<view class="bar" :style="{left:leftBar+'rpx'}"></view>
		</view>
		<view class="goods-item" v-for="(item,index) in list" :key="item.id">
			<view class="goods">
				<image :src="item.thumb_image_text" class="goods-img" mode=""></image>
				<view class="goods-content">
					<view class="goods-name">{{item.name}}</view>
					<view class="goods-tag">单规格</view>
				</view>
			</view>
			<view class="goods-action" v-if="current == 0 || current == 2">
				<view class="action-item">
					<image src="/static/images/user/icon_up.png"></image>
					<text>下架</text>
				</view>
				<view class="action-item">
					<image src="/static/images/user/icon_see.png"></image>
					<text>预览 </text>
				</view>
				<view class="action-item">
					<image src="/static/images/user/icon_edit.png"></image>
					<text>编辑</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				current: 1,
				params: {
					state: 0,
					page: 1,
					pageSize: 20,
				},
				list: []
			};
		},
		computed: {
			leftBar() {
				switch (this.current) {
					case 0:
						return 68
					case 2:
						return 236
					case 1:
						return 428
					case 3:
						return 640
				}
				return
			}
		},
		onLoad(option) {
			if (option.state) {
				this.current = +option.state
			}
			this.mylists()
		},
		onReachBottom() {
			this.params.page++
			this.mylists()
		},
		methods: {
			mylists() {
				uni.request({
					url: '/xilumarket.recovery/mylists',
					method: 'GET',
					data: this.params,
					success: ({
						data
					}) => {
						let res = data
						console.log(res)
						if (this.params.page == 1) {
							this.list = res.data
						} else {
							this.list = [...this.list, ...res.data]
						}
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.tab-box {
		display: flex;
		align-items: center;
		padding: 24rpx;
		justify-content: space-between;
		background: #fff;
		top: 0;
		z-index: 9;
		font-size: 28rpx;
		color: #999;
		position: relative;
		transition: all .3s;

		.active {
			color: #ef5d0f;
			font-weight: 800;
		}

		.bar {
			position: absolute;
			bottom: 0;
			left: 68rpx;
			width: 48rpx;
			height: 4rpx;
			transition: all .3s;
			background: #EF5D0F;
		}
	}

	.goods-item {
		width: 696rpx;
		background: #FFFFFF;
		border-radius: 20rpx;
		margin: 20rpx auto;

		.goods {
			padding: 30rpx 26rpx;
			border-bottom: 1px solid #f5f5f5;
			font-size: 28rpx;
			color: #333;
			font-weight: 500;

			.goods-img {
				width: 160rpx;
				height: 160rpx;
			}

			.goods-name {
				display: -webkit-box;
				-webkit-line-clamp: 2;
				/* 设置你想显示的最大行数 */
				-webkit-box-orient: vertical;
				overflow: hidden;
				text-overflow: ellipsis;
				width: 100%;
			}

			.goods-content {
				height: 160rpx;
				display: inline-flex;
				vertical-align: top;
				margin-left: 20rpx;
				flex-direction: column;
				justify-content: space-between;
				width: calc(100% - 180rpx);
			}

			.goods-tag {
				width: 104rpx;
				height: 48rpx;
				background: #FFFFFF;
				border-radius: 8rpx;
				border: 2rpx solid #FF1111;
				font-weight: 500;
				font-size: 28rpx;
				color: #FF1111;
				line-height: 48rpx;
				text-align: center;
			}
		}

		.goods-action {
			padding: 30rpx 20rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;

			.action-item {
				color: #333;
				font-size: 28rpx;

				text {
					margin-left: 10rpx;
					vertical-align: top;
				}

				image {
					width: 40rpx;
					height: 40rpx;
				}
			}
		}
	}
</style>